package com.foreknow.test;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class ListDemo {
    public static void main(String[] args) {
        //创建一个List集合
        List<String> list = new ArrayList<>();
        //向集合中添加一个元素
        list.add("1");
        list.add("fender");
        list.add("true");
        list.add("3.14");
        //从集合中获取某个元素
        String name = list.get(1);
        System.out.println(name);
        //创建一个List集合并向集合中添加两个员工
        List<Employee> list1 = new ArrayList<>();
        Employee e1  = new Employee();
        e1.setEid(1001);
        e1.setName("fender");
        Employee e2  = new Employee();
        e2.setEid(1002);
        e2.setName("gibson");
        //向集合中添加元素
        list1.add(e1);
        list1.add(e2);
        //从集合中获取元素
        Employee e = list1.get(0);
        System.out.println(e.getEid() + "---" + e.getName());
        //遍历集合
        System.out.println("----------------------for循环-------------------------");
        for (int i = 0;i<list1.size();i++) {
            Employee employee = list1.get(i);
            System.out.println(employee.getEid() + "---" + employee.getName());
        }

        System.out.println("----------------------增强for循环----------------------");
        for (Employee employee:list1) {
            System.out.println(employee.getEid() + "---" + employee.getName());
        }

        System.out.println("----------------------迭代器---------------------------");
        Iterator<Employee> it = list1.iterator();
        while (it.hasNext()) {
            Employee employee = it.next();
            System.out.println(employee.getEid() + "---" + employee.getName());
        }







    }
}
